from django.db import models

# Create your models here.

from django.db import models


# 气体类型
class AirType(models.Model):
    name = models.CharField('气体类型', max_length=200)


    class Meta:
        verbose_name = '气体类型'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.name

# 气瓶状态
class State(models.Model):
    name = models.CharField('气瓶状态', max_length=200)


    class Meta:
        verbose_name = '气瓶状态'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.name

# 气瓶容量
class Size(models.Model):
    name = models.CharField('气瓶容量', max_length=200)



    class Meta:
        verbose_name = '气瓶容量'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.name

# 人员
class Person(models.Model):
    name = models.CharField('姓名', max_length=200)
    key = models.CharField('密钥', max_length=200, unique=True)

    class Meta:
        verbose_name = '用户'
        verbose_name_plural = verbose_name
    def __str__(self):
        return self.name

# 科室
class KeShi(models.Model):  #科室
    name = models.CharField('科室名称', max_length=200)   #科室名称
    loc = models.CharField('科室位置', max_length=200)    #科室位置
    class Meta:
        verbose_name = '科室'
        verbose_name_plural = verbose_name
    def __str__(self):
        return self.name

# 气瓶
class Bottle(models.Model):
    type = models.ForeignKey(AirType, on_delete=models.CASCADE, verbose_name='气体类型')
    state = models.ForeignKey(State, on_delete=models.CASCADE, verbose_name='气瓶状态')
    size = models.ForeignKey(Size, on_delete=models.CASCADE, verbose_name='气瓶容量')
    name = models.CharField('气瓶名称', max_length=200)
    uid = models.CharField('气瓶UID', max_length=200, unique=True)
    bro_date = models.DateField('出厂时间')
    loc = models.ForeignKey(KeShi, on_delete=models.CASCADE, verbose_name='气瓶位置')

    class Meta:
        verbose_name = '气瓶'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.name


# 日志
class Log(models.Model):        #变更日志
    person = models.ForeignKey(Person, on_delete=models.CASCADE, verbose_name='姓名')
    date = models.DateTimeField('变更时间', auto_now_add=True)
    bottle = models.ForeignKey(Bottle, on_delete=models.CASCADE, verbose_name='气瓶')
    loc = models.ForeignKey(KeShi, on_delete=models.CASCADE, verbose_name='位置')
    state = models.ForeignKey(State, on_delete=models.CASCADE, verbose_name='状态')
    class Meta:
        verbose_name = '气瓶日志'
        verbose_name_plural = verbose_name

    def __str__(self):
        return str(self.date)[:19]
